//
//  EmoticonAttachment.swift
//  emoticon模块代码
//
//  Created by rong on 15/7/9.
//  Copyright © 2015年 rong. All rights reserved.
//

import UIKit

class EmoticonAttachment: NSTextAttachment {
    
        //用这个变量来记录  表情文字
        var chs: String?
        
        class func emoticonString(emoticon: Emoticon, font: UIFont) -> NSAttributedString {
        
        let attachment = EmoticonAttachment() //NSTextAttachment()
        attachment.chs = emoticon.chs
        attachment.image = UIImage(contentsOfFile: emoticon.imgPath!)
        let s = font.lineHeight
        attachment.bounds = CGRect(x: 0, y: -4, width: s, height: s)
        
        //生成一个属性文本
        let attrString = NSAttributedString(attachment: attachment)
            
        //生成可变文本 － 设置字体
        //获得文本框完整的属性文本
        let strM = NSMutableAttributedString(attributedString: attrString)
        strM.addAttributes([NSFontAttributeName : font], range: NSMakeRange(0, 1))
            
        return strM
    }
}
